﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Purdue.Enums;
using Purdue.Infrastructure;
using System.Data.Linq.Mapping;

namespace Purdue.Models
{
    [Table(Name = "Loginlogs")]
    public partial class LoginInfo : NotificationObject
    {
        public LoginInfo() { }

        #region Fields
        private Int64 id;
        private string account;
        private LoginAccountKindValue accountKind = LoginAccountKindValue.Customer;
        private DateTime time = DateTime.Now;
        private string ip = HttpContext.Current.Request.UserHostAddress;
        private string dns = HttpContext.Current.Request.UserHostName;
        private string browser = HttpContext.Current.Request.Browser.Browser;
        private string browserVersion = HttpContext.Current.Request.Browser.Version;
        private string platform = HttpContext.Current.Request.Browser.Platform;
        private bool mobile = HttpContext.Current.Request.Browser.IsMobileDevice;
        private string os;
        private string remoteUsername;
        private string remoteMachineName;
        private LoginResultValue result = LoginResultValue.None;
        #endregion

        #region Properties
        /// <summary>
        /// 编号
        /// </summary>
        [Column(Name = "Id", IsPrimaryKey = true, CanBeNull = false, IsDbGenerated = true, DbType = "BIGINT NOT NULL Identity", AutoSync = AutoSync.OnInsert)]
        public Int64 Id
        {
            get { return id; }
            set
            {
                id = value;
                RaisePropertyChanged(() => Id);
            }
        }

        /// <summary>
        /// 账号
        /// </summary>
        [Column]
        public string Account
        {
            get { return account; }
            set
            {
                account = value;
                RaisePropertyChanged(() => Account);
            }
        }

        /// <summary>
        /// 登录账号类型
        /// </summary>
        [Column(Name = "AccountKind", DbType = "INT NOT NULL", CanBeNull = false)]
        public LoginAccountKindValue AccountKind
        {
            get { return accountKind; }
            set
            {
                accountKind = value;
                RaisePropertyChanged(() => AccountKind);
            }
        }

        /// <summary>
        /// 登录时间
        /// </summary>
        [Column(Name="LTime")]
        public DateTime Time
        {
            get { return time; }
            set
            {
                time = value;
                RaisePropertyChanged(() => Time);
            }
        }

        /// <summary>
        /// IP地址
        /// </summary>
        [Column]
        public string IP
        {
            get { return ip; }
            set
            {
                ip = value;
                RaisePropertyChanged(() => IP);
            }
        }

        /// <summary>
        /// DNS
        /// </summary>
        [Column]
        public string DNS
        {
            get { return dns; }
            set
            {
                dns = value;
                RaisePropertyChanged(() => DNS);
            }
        }

        /// <summary>
        /// 浏览器
        /// </summary>
        [Column]
        public string Browser
        {
            get { return browser; }
            set
            {
                browser = value;
                RaisePropertyChanged(() => Browser);
            }
        }

        /// <summary>
        /// 浏览器版本
        /// </summary>
        [Column]
        public string BrowserVersion
        {
            get { return browserVersion; }
            set
            {
                browserVersion = value;
                RaisePropertyChanged(() => BrowserVersion);
            }
        }

        /// <summary>
        /// 平台
        /// </summary>
        [Column]
        public string Platform
        {
            get { return platform; }
            set
            {
                platform = value;
                RaisePropertyChanged(() => Platform);
            }
        }

        /// <summary>
        /// 是否移动设备
        /// </summary>
        [Column]
        public bool Mobile
        {
            get { return mobile; }
            set
            {
                mobile = value;
                RaisePropertyChanged(() => Mobile);
            }
        }

        /// <summary>
        /// 操作系统
        /// </summary>
        [Column]
        public string OS
        {
            get { return os; }
            set
            {
                os = value;
                RaisePropertyChanged(() => OS);
            }
        }

        /// <summary>
        /// 远程用户名
        /// </summary>
        [Column]
        public string RemoteUsername
        {
            get { return remoteUsername; }
            set
            {
                remoteUsername = value;
                RaisePropertyChanged(() => RemoteUsername);
            }
        }

        /// <summary>
        /// 机器名称
        /// </summary>
        [Column]
        public string RemoteMachinename
        {
            get { return remoteMachineName; }
            set
            {
                remoteMachineName = value;
                RaisePropertyChanged(() => RemoteMachinename);
            }
        }

        /// <summary>
        /// 登录结果
        /// </summary>
        [Column]
        public LoginResultValue Result
        {
            get { return result; }
            set
            {
                result = value;
                RaisePropertyChanged(() => Result);
            }
        }
        #endregion
    }
}
